﻿Imports capaNegocios

Public Class secHorario_modificar
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.lblGradoDetalle.Text = Request.QueryString("grado")
        Me.lblNivelDetalle.Text = Request.QueryString("nivel")
        Me.lblSeccionDetalle.Text = Request.QueryString("seccion")

        If Page.IsPostBack = False Then
            CargarComboCurso()
        End If

        Dim objHorario As clsHorario = New clsHorario()
        Dim registros As DataRowCollection = objHorario.Buscar(Me.lblGradoDetalle.Text, Date.Now.Year.ToString, Me.lblSeccionDetalle.Text).Rows
        dgvHorario.DataSource = objHorario.CrearHorario(registros)
        dgvHorario.DataBind()
    End Sub

    Protected Sub btnModificarHorario_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnModificarHorario.Click
        Dim nombre, curso, dia, hInicio, hFinal, nivel, grado, seccion, anio As String
        Dim objHorario As clsHorario = New clsHorario()

        curso = Me.ddlCursoModificar.SelectedValue
        dia = Me.ddlDiaModificar.SelectedValue.ToString
        nivel = Me.lblNivelDetalle.Text
        grado = Me.lblGradoDetalle.Text
        seccion = Me.lblSeccionDetalle.Text
        anio = Convert.ToString(Date.Now.Year)
        nombre = nivel & "-" & anio & "-" & grado & "-" & seccion
        hInicio = ddlHoraInicioModificar.Text & ":" & ddlMinutoInicioModificar.Text
        hFinal = ddlHoraFinalModificar.Text & ":" & ddlMinutoFinalModificar.Text

        objHorario.nombre = nombre
        objHorario.dia = dia
        objHorario.horaInicio = hInicio
        objHorario.horaFinal = hFinal

        objHorario.Agregar(curso, anio, grado, seccion)

        Dim registros As DataRowCollection = objHorario.Buscar(Me.lblGradoDetalle.Text, Date.Now.Year.ToString, Me.lblSeccionDetalle.Text).Rows
        dgvHorario.DataSource = objHorario.CrearHorario(registros)
        dgvHorario.DataBind()
    End Sub

    Private Sub CargarComboCurso()
        Dim objCurso As clsCurso = New clsCurso()
        Me.ddlCursoModificar.Items.Clear()
        For Each fila As DataRow In objCurso.Buscar.Rows
            Me.ddlCursoModificar.Items.Add(New ListItem(fila("CUR_Nombre"), fila("CUR_ID")))
        Next
    End Sub
End Class